package com.myblog.myblog.utils;

import java.io.Serializable;

/**
 * @author gyl
 * @data 2020/3/29 1:22
 */
public class ResultData implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 状态码 0:表示成功 -1:表示失败
     */
    private Integer code;

    /**
     * 返回的数据
     */
    private Object data;

    /**
     * 返回的描述
     */
    private String msg;

    public ResultData(Integer code, Object data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    /**
     * 成功 传入空数据
     * @return
     */
    public static ResultData success(){
        return new ResultData(0, null, "success");
    }
    /**
     * 成功 传入数据
     * @param data
     * @return
     */
    public static ResultData success(Object data){
        return new ResultData(0, data, "success");
    }

    /**
     * 失败 传入描述信息
     * @param msg
     * @return
     */
    public static ResultData fail(String msg){
        return new ResultData(-1, null, msg);
    }

    /**
     * 失败 传入状态码 描述信息
     * @param code
     * @param msg
     * @return
     */
    public static  ResultData fail(Integer code, String msg){
        return new ResultData(code, null, msg);
    }

    /**
     * 成功 传入状态码 数据
     * @param code
     * @param data
     * @return
     */
    public static ResultData success(Integer code, Object data){
        return new ResultData(code, data, "success");
    }

    /**
     * 成功 传入数据 描述信息
     * @param msg
     * @param data
     * @return
     */
    public static ResultData success(Object data, String msg){
        return new ResultData(0, data, msg);
    }

    /**
     * 成功 传入状态码 数据 描述信息
     * @param code
     * @param data
     * @return
     */
    public static ResultData success(Integer code, Object data, String msg){
        return new ResultData(code, data, msg);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "ResultData [code=" + code + ", data=" + data + ", msg=" + msg + "]";
    }
}